package com.zjmzxfzhl.modules.flowable.controller;

import com.zjmzxfzhl.common.core.base.BaseController;
import com.zjmzxfzhl.modules.flowable.common.SysCodeInfo;
import io.dshubs.commons.tools.utils.Result;
import io.dshubs.dto.SysDictDataDTO;
import io.dshubs.feign.DictFeignClient;
import io.swagger.annotations.Api;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: yu
 * @Date: 2021/08/18/18:15
 */
@RestController
@Api(tags = "字典管理")
@RequestMapping("/sys/codeInfo")
public class SysCodeInfoController extends BaseController {
    @Autowired
    private DictFeignClient dictFeignClient;

//    @GetMapping("/getSysCodeInfos")
//    @ApiOperation("通过字典类型查询字典数据")
//    public Result<List<SysDictDataDTO>> getDictDataByDictType(String codeTypeIds) {
//        return dictFeignClient.getDictByType(codeTypeIds);
//    }

    /**
     * 根据代码类型查询代码信息清单
     *
     * @param codeTypeIds
     * @return
     */
    @GetMapping(value = "/getSysCodeInfos")
    public com.zjmzxfzhl.common.core.Result getSysCodeInfos(String codeTypeIds) {
        Map<String, List<SysCodeInfo>> resMap = new HashMap<>();
        List<SysCodeInfo> list = new ArrayList<>();
         Result<List<SysDictDataDTO>> dictByType = dictFeignClient.getDictByType(codeTypeIds);
        List<SysDictDataDTO> dictByTypeData = dictByType.getData();
        if(CollectionUtils.isNotEmpty(dictByTypeData)) {
            dictByTypeData.forEach(dict->{
                SysCodeInfo sysCodeInfo = new SysCodeInfo();
                sysCodeInfo.setCodeInfoId(dict.getId().toString());
                sysCodeInfo.setCodeTypeId(dict.getDictType());
                sysCodeInfo.setContent(dict.getDictValue());
                sysCodeInfo.setValue(dict.getDictValue());
                list.add(sysCodeInfo);
            });
        }
        resMap.put("processCategory",list);
        return com.zjmzxfzhl.common.core.Result.ok(resMap);
    }
}
